#!/usr/bin/python
#Kudasai - The MSN/Windows Live Messenger Server
#Kudasai is released under the MIT License.
#A copy of the MIT License is available in the i9 SVN Repository

from Kamaelia.Internet.SingleServer import SingleServer
from Kamaelia.Internet.TCPClient import TCPClient
from Kamaelia.Util.Console import ConsoleEchoer
from Kamaelia.Util.Console import ConsoleReader
from Kamaelia.Chassis.Pipeline import Pipeline

#Experimental
from Kamaelia.Chassis.Graphline import Graphline
#End Experimental

from FileAppender import Append

#Open a TCP socket on port 1863 and sit, until we get version info
#Looks like Pidgin gives us "VER 0 MSNP11 MSNP10 CVR0", although there are other versions (need more clients to try)
#We can also do the MSN 1.0 protocol, which is slightly easier, and has a weird LDAP-esque extension (yay!?)
outputfile = "KUDASAI_DEBUG.LOG"
protocol = Pipeline(
		Append(filename=outputfile),
                ConsoleEchoer(forwarder=True),		
                ConsoleReader(prompt="",eol="\r\n"),
		Append(filename=outputfile),	
           )
Graphline(
         SERVER = SingleServer(port=1863),
         PROTOCOL = protocol,
         linkages = {
            ("SERVER", "outbox") : ("PROTOCOL", "inbox"), #Links server to Console* stuff
            ("PROTOCOL", "outbox") : ("SERVER", "inbox"), #Links Console* stuff to server
         }
).run()

#What we know... 

#MSN 1.0 LDAP Extension: FND 8 fname=Test lname=User city=* state=* country=*
#Substitute an option for a wildcard to display all the data available

#http://paster.dazjorz.com/?a=rawpaste&p=3394 Pretty much describes what's needed (protocol-wise) to get MSN Messenger 1.0 up onto the server, and assigned a "friendly name"...
#More documentation at http://pastebin.org/58808 (MSN Messenger Service 1.0 Protocol) - a copy of this is also included here

#Playing with 'nc -k -l -C 1863', we can "replay" the client's version string, and then get issued something like 
#"CVR 1 0x0409 winnt 5.1 i386 MSNMSGR 7.0.0816 MSMSGS test@example.com"
#What do we do when we get this?

